#include "nodestats.h"
#include <QFile>
#include <QDebug>

NodeStats::NodeStats()
{    
    histogram = new QVector<int>();
    histogramValue = new QVector<double>();
    mean = 0.0;
    variance = 0.0;
    min = 0.0;
    max = 0.0;
    cnt = 0;
}

NodeStats::~NodeStats()
{
    if(histogram)
    {
        delete histogram;
    }

    if(histogramValue)
    {
        delete histogramValue;
    }
}

void NodeStats::saveStats(QString path)
{
    QFile file(path);
    file.open(QIODevice::WriteOnly | QIODevice::Text);
    QTextStream out(&file);

    out << "mean:" << mean << endl;
    out << "variance:" << variance<< endl;
    out << "min:" << min << endl;
    out << "max:" << max << endl;
    out << endl;

    // data
    for(int i = 0; i < cnt; i++)
    {
        out << histogramValue->value(i) << " " << histogram->value(i) << endl;
    }

    file.close();
}
